﻿using System;

namespace CSharp.Exam3
{
    class FindWord
    {
        public static void Test()
        {
            int startIndex = 0, i = 0, count = 0;
            string text, word;

            do
            {
                Console.WriteLine("Enter String: ");
                text = Console.ReadLine();
            } while (text == string.Empty);

            do
            {
                Console.WriteLine("Enter Word: ");
                word = Console.ReadLine();
            } while (word == string.Empty);

            do
            {
                i = text.IndexOf(word, startIndex);

                if (i > -1)
                {
                    count++;
                    startIndex = i + word.Length;
                }
            } while (i > -1);

            Console.Write("Found {0} times", count);
        }
    }
}
